package l1j.opqlo.NewSystem.ItemStatus;

import java.util.HashMap;
import java.util.Set;

import l1j.opqlo.NewSystem.ItemLevelUp.LevelStatus;
import l1j.server.server.datatables.PetItemTable;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.templates.L1Armor;
import l1j.server.server.templates.L1Item;
import l1j.server.server.templates.L1PetItem;
import l1j.server.server.utils.BinaryOutputStream;

public class L1ItemStatus {

	private final L1ItemInstance _itemInstance;

	private final L1Item _item;

	private final BinaryOutputStream _os;

	private final LevelStatus _LvStatus;

	private final int _itemId;

	/**
	 * 物品詳細資料
	 *
	 * @param template
	 *            L1Item
	 */
	public L1ItemStatus(final L1Item template) {
		this._itemInstance = new L1ItemInstance();
		this._itemInstance.setItem(template);
		this._item = template;
		this._os = new BinaryOutputStream();
		this._LvStatus = this._itemInstance.getLvStatus();
		this._itemId = this._itemInstance.getItemId();
	}

	/**
	 * 物品詳細資料
	 *
	 * @param itemInstance
	 *            L1ItemInstance
	 */

	public L1ItemStatus(final L1ItemInstance itemInstance) {
		this._itemInstance = itemInstance;
		this._item = itemInstance.getItem();
		this._os = new BinaryOutputStream();
		this._LvStatus = this._itemInstance.getLvStatus();
		this._itemId = this._itemInstance.getItemId();

	}

	private BinaryOutputStream armor() {
		// AC
		this._os.writeC(19);
		int ac = ((L1Armor) this._item).get_ac();
		if (ac < 0) {
			ac = ac - ac - ac;
		}
		// TODO 防具の材料が表示されない不具合修正byl1j-jp2日方團隊
		this._os.writeC(ac);
		// TODO 防具の材料が表示されない不具合修正byl1j-jp2日方團隊
		this._os.writeC(this._item.getMaterial());
		// TODO 装飾品グレード 0:上等 1:中等 2:初等 3:特等
		if (this._item.getType2() == 2 && this._item.getType() >= 8
				&& this._item.getType() <= 12) {
			this._os.writeC(((L1Armor) this._item).getGrade());
		} else {
			this._os.writeC(-1);
		}
		this._os.writeD(this._itemInstance.getWeight());

		// 強化数
		// TODO 飾品強化卷軸
		if (this._itemInstance.getEnchantLevel() != 0) {
			this._os.writeC(2);
			if (this._item.getType() == 8 || this._item.getType() == 9
					|| this._item.getType() == 10 || this._item.getType() == 12) {
				this._os.writeC(0);
			} else {
				this._os.writeC(this._itemInstance.getEnchantLevel());
			}
		}
		// TODO 飾品強化卷軸

		// 損傷度
		if (this._itemInstance.get_durability() != 0) {
			this._os.writeC(3);
			this._os.writeC(this._itemInstance.get_durability());
		}

		final int HitMod = this._item.getHitModifierByArmor()
				+ this._LvStatus.getLvHitModifier();
		if (HitMod != 0) {
			// os.writeC(5);
			// os.writeC(getItem().getHitModifierByArmor());
			this._os.writeC(39);
			if (HitMod > 0) {
				this._os.writeS("攻擊成功 +" + HitMod);
			} else {
				this._os.writeS("攻擊成功 " + HitMod);
			}
		}
		final int DmgMod = this._item.getDmgModifierByArmor()
				+ this._LvStatus.getLvDmgModifier();
		if (DmgMod != 0) {
			// os.writeC(6);
			// os.writeC(getItem().getDmgModifierByArmor());
			this._os.writeC(39);
			if (DmgMod > 0) {
				this._os.writeS("額外攻擊點數 +" + DmgMod);
			} else {
				this._os.writeS("額外攻擊點數 " + DmgMod);
			}
		}

		// 弓の命中率補正
		if (this._item.getBowHitModifierByArmor() != 0) {
			this._os.writeC(24);
			this._os.writeC(this._item.getBowHitModifierByArmor());
		}
		// 弓のダメージ補正
		if (this._item.getBowDmgModifierByArmor() != 0) {
			//			this._os.writeC(35);
			//			this._os.writeC(this._item.getBowDmgModifierByArmor());
			this._os.writeC(39);
			this._os.writeS("遠距離攻擊 +" + this._item.getBowDmgModifierByArmor());
		}
		/** opqlo種族相剋 */
		/*
		 * final int sktp = _itemInstance.getSkillType(); if(sktp >0){ String
		 * msg = ""; switch(sktp){ case 1: msg =
		 * "不死族增傷 "+_itemInstance.getLevel()+" %";break; case 2: msg =
		 * "惡魔族增傷 "+_itemInstance.getLevel()+" %";break; case 3: msg =
		 * "頭目族增傷 "+_itemInstance.getLevel()+" %";break; case 4: msg =
		 * "狼族增傷 "+_itemInstance.getLevel()+" %";break; case 5: msg =
		 * "龍族增傷 "+_itemInstance.getLevel()+" %";break; case 6: msg =
		 * "無種族增傷 "+_itemInstance.getLevel()+" %";break; case 7: msg =
		 * "小型怪增傷 "+_itemInstance.getLevel()+" %";break; case 8: msg =
		 * "大型怪增傷 "+_itemInstance.getLevel()+" %";break; } _os.writeC(39);
		 * _os.writeS(msg); } /** opqlo種族相剋
		 */

		this.OtherStatus();

		return this._os;

	}

	private BinaryOutputStream etcitem() {
//
//		if(true){
//			this._os.writeC(39);
//			this._os.writeS("一二三四五六七八九十一");
//			this._os.writeC(39);
//			this._os.writeS("第二行");
//			this._os.writeC(39);
//			this._os.writeS("第三行");
//			this._os.writeC(39);
//			this._os.writeS("第四行");
//			this._os.writeC(39);
//			this._os.writeS("第五行");
//			this._os.writeC(39);
//			this._os.writeS("第六行");
//			this._os.writeC(39);
//			this._os.writeS("第七行");
//			this._os.writeC(39);
//			this._os.writeS("第八行");
//			this._os.writeC(39);
//			this._os.writeS("第九行");
//			this._os.writeC(39);
//			this._os.writeS("第十行");
//			this._os.writeC(39);
//			this._os.writeS("第十一行");
//			this._os.writeC(39);
//			this._os.writeS("第十二行");
//			this._os.writeC(39);
//			this._os.writeS("第十三行");
//			this._os.writeC(39);
//			this._os.writeS("第十四行");
//			this._os.writeC(39);
//			this._os.writeS("第十五行");
//			this._os.writeC(39);
//			this._os.writeS("第十六行");
//			this._os.writeC(39);
//			this._os.writeS("第十七行");
//			this._os.writeC(39);
//			this._os.writeS("第十八行");
//			return this._os;
//		}else{

			switch (this._item.getType()) {
			case 2: // light
				this._os.writeC(22); // 明るさ
				this._os.writeH(this._item.getLightRange());
				break;
			case 7: // food
				this._os.writeC(21);
				// 栄養
				this._os.writeH(this._item.getFoodVolume());
				break;
			case 0: // arrow
			case 15: // sting
				//			this._os.writeC(1); // 打撃値
				//			this._os.writeC(this._item.getDmgSmall());
				//			this._os.writeC(this._item.getDmgLarge());
				this._os.writeC(39);
				this._os.writeS("攻擊力 " +this._item.getDmgSmall()+ " / "+this._item.getDmgLarge());
				break;
			default:
				this._os.writeC(23); // 材質
				break;
			}
			this._os.writeC(this._item.getMaterial());
			this._os.writeD(this._itemInstance.getWeight());

			// opqlo 新增物品自訂描述
			final ItemStatusTable check = ItemStatusTable.getInstance()
					.getTemplate(this._itemId);
			if (check != null) {
				this._os.writeC(39);
				this._os.writeS(check.getItemStatusMsg(this._itemId));
			}
			// opqlo 新增物品自訂描述

			return this._os;
//		}
	}

	public BinaryOutputStream getStatusBytes() {

		final L1PetItem petItem = PetItemTable.getInstance().getTemplate(
				this._itemId);
		if (petItem != null) { // 寵物裝備
			return this.petitem(petItem);
		}
		switch (this._item.getType2()) {

		case 0: // etcitem
			return this.etcitem();

		case 1: // weapon
			return this.weapon();

		case 2: // armor
			return this.armor();
		}

		return null;
	}

	private void OtherStatus() {

		if (this._item.get_safeenchant() >= 0) {
			this._os.writeC(39);
			this._os.writeS("強化安定值: " + this._item.get_safeenchant());
		}

		if (this._itemInstance.getItemId() == 800000) {
			this._os.writeC(39);
			this._os.writeS("經驗增加: 50%");
			this._os.writeC(39);
			this._os.writeS("積分獲得增加: 50%");
			this._os.writeC(39);
			this._os.writeS("金幣掉落增加: 50%");

		}

		if (this._itemInstance.getExpUp() > 0) {

			final int exprate = (int) (this._itemInstance.getExpUp() * 100D);
			this._os.writeC(39);
			this._os.writeS("經驗增加: " + exprate + "%");

		}

		/** opqlo 掉寶率 */
		final double droprate = (this._itemInstance.getDroprate()
				+ this._item.getDroprate() + this._LvStatus.get掉寶率()) * 100;

		if (droprate != 0) {
			this._os.writeC(39);
			this._os.writeS("掉寶率提升:" + droprate + "%");
		}
		/** opqlo 金幣率 */

		final double 金幣倍率 = this._LvStatus.get金幣率() * 100;

		if (金幣倍率 != 0) {
			this._os.writeC(39);
			this._os.writeS("金幣掉落增加:" + 金幣倍率 + "%");
		}

		if (this._itemInstance.getBigDmg() > 0) {
			final int dmgrate = this._itemInstance.getBigDmg();
			this._os.writeC(39);
			this._os.writeS("大型怪增傷 " + dmgrate + " %");
		}
		if (this._itemInstance.getSmallDmg() > 0) {
			final int dmgrate = this._itemInstance.getSmallDmg();
			this._os.writeC(39);
			this._os.writeS("小型怪增傷 " + dmgrate + " %");
		}

		final int extradmg = this._LvStatus.getLvExtraDmg()
				+ this._item.getExtraDmg() + this._itemInstance.getExtraDmg();
		final int extradef = this._LvStatus.getLvExtraDef()
				+ this._item.getExtraDef() + this._itemInstance.getExtraDef();
		if (extradmg != 0 || extradef != 0) {
			this._os.writeC(39);
			if (extradmg != 0 && extradef != 0) {
				this._os.writeS("破甲/抵擋:" + extradmg + " / " + extradef);
			} else if (extradef != 0) {
				this._os.writeS("抵擋:" + extradef);
			} else {
				this._os.writeS("破甲:" + extradmg);
			}
		}
		/*
		 * if ( extradef !=0 ){ _os.writeC(39); _os.writeS("抵擋值:"+(extradef)); }
		 */

		final int WeaponMagicDmg = this._LvStatus.getLvFixDmg()
				+ this._LvStatus.getLvRandomDmg();
		if (WeaponMagicDmg != 0) {
			this._os.writeC(39);
			this._os.writeS("武器魔法傷害+" + WeaponMagicDmg);
		}
		final int magicdmg = this._item.getMagicDmgModifier()
				+ this._LvStatus.getLvMagicDmgModifier() + this._itemInstance.getMagicDmgMod();
		if (magicdmg != 0) {
			this._os.writeC(39);
			this._os.writeS("法術增傷+" + magicdmg);
		}
		/*
		 * final int Reduction = getItem().getDamageReduction() + _dmgreduction;
		 * if(Reduction >0){ os.writeC(39); os.writeS("傷害減少:"+ Reduction); }
		 */

		// 使用可能
		int bit = 0;
		bit |= this._item.isUseRoyal() ? 1 : 0;
		bit |= this._item.isUseKnight() ? 2 : 0;
		bit |= this._item.isUseElf() ? 4 : 0;
		bit |= this._item.isUseMage() ? 8 : 0;
		bit |= this._item.isUseDarkelf() ? 16 : 0;
		bit |= this._item.isUseDragonknight() ? 32 : 0;
		bit |= this._item.isUseIllusionist() ? 64 : 0;
		// bit |= _item.isUseHiPet() ? 64 : 0; // ハイペット
		this._os.writeC(7);
		this._os.writeC(bit);

		switch (this._itemId) {
		case 126: // 瑪那魔杖
		case 127: // 鋼鐵瑪那魔杖
		case 581:
		case 588:
		case 595:
		case 602:
		case 609:
		case 616:
		case 623:
		case 630:
		case 652:
		case 660:
			this._os.writeC(16);
			break;
		}
		// MP吸収
		/*
		 * if (_itemId == 126 || _itemId == 127) { // マナスタッフ、鋼鉄のマナスタッフ
		 * _os.writeC(16); }
		 */
		// HP吸収
		if (this._itemId == 262) { // ディストラクション
			this._os.writeC(34);
		}

		final LevelStatus lvs = this._itemInstance.getLvStatus();
		if (lvs.EthnicityIsNull() == false) {
			/**
			 * 種族傷害取得 0=普通、1=不死系、2=惡魔系、3=BOSS系、4=亡靈系、5=狼人系、6=龍系、7=人類
			 */

			for (int i = 0; i <= ItemStatusName.EthnicityMax; i++) {
				final double dmg = lvs.getEthnicityDmg(i);
				if (dmg == 0) {
					continue;
				}
				final ItemStatusName name = ItemStatusName.get();
				this._os.writeC(39);
				final int totaldmg = (int) (dmg * 100);
				this._os.writeS(name.getEthnicityName(i) + totaldmg + " %");

			}
		}
		if (lvs.AttrIsNull() == false) {
			/**
			 * 屬性增傷 //1=地、2=火、4=水、5=光、6=闇、8=風
			 */
			final int[] attrlist = { 1, 2, 4, 5, 6, 8 };
			for (final int element : attrlist) {
				final double dmg = lvs.getAttrDmg(element);
				if (dmg <= 0) {
					continue;
				}
				final ItemStatusName name = ItemStatusName.get();
				final int totaldmg = (int) (dmg * 100);
				this._os.writeC(39);
				this._os.writeS(name.getAttrName(element) + totaldmg + " %");
			}
		}

		if(!lvs.getAttrDef().isEmpty()){
			/**
			 * 屬性減傷 //1=地、2=火、4=水、5=光、6=闇、8=風
			 */
			final HashMap<Integer , Double>attrdef = lvs.getAttrDef();
			final Set<Integer>attrdefkey = attrdef.keySet();
			for (final int key : attrdefkey) {
				final double dmg = attrdef.get(key);
				if (dmg <= 0) {
					continue;
				}
				final ItemStatusName name = ItemStatusName.get();
				final int totaldmg = (int) (dmg * 100);
				this._os.writeC(39);
				this._os.writeS(name.getAttrDefName(key) + totaldmg + " %");
			}
		}


		// STR~CHA
		/**
		 * 六屬性加成設定 順序: 力=0敏=1智=2精=3體=4魅=5
		 */

		final int str = this._item.get_addstr() + this._LvStatus.getLvStr()
				+ lvs.getStatus(0);
		if (str != 0) {
			this._os.writeC(8);
			this._os.writeC(str);
		}
		final int dex = this._item.get_adddex() + this._LvStatus.getLvDex()
				+ lvs.getStatus(1);
		if (dex != 0) {
			this._os.writeC(9);
			this._os.writeC(dex);
		}
		final int Int = this._item.get_addint() + this._LvStatus.getLvInt()
				+ lvs.getStatus(2);
		if (Int != 0) {
			this._os.writeC(12);
			this._os.writeC(Int);
		}
		final int wis = this._item.get_addwis() + this._LvStatus.getLvWis()
				+ lvs.getStatus(3);
		if (wis != 0) {
			this._os.writeC(11);
			this._os.writeC(wis);
		}
		final int con = this._item.get_addcon() + this._LvStatus.getLvCon()
				+ lvs.getStatus(4);
		if (con != 0) {
			this._os.writeC(10);
			this._os.writeC(con);
		}
		final int cha = this._item.get_addcha() + lvs.getStatus(5);
		if (cha != 0) {
			this._os.writeC(13);
			this._os.writeC(cha);
		}
		/*
		 * if (_item.get_addstr() != 0 || _LvStatus.getLvStr() !=0) {//opqlo
		 * 道具升級系統 //if (_item.get_addstr() != 0) { _os.writeC(8);
		 * //os.writeC(_item.get_addstr());
		 * _os.writeC(_item.get_addstr()+_LvStatus.getLvStr());//opqlo 道具升級系統 }
		 * if (_item.get_adddex() != 0 || _LvStatus.getLvDex() !=0) { //if
		 * (_item.get_adddex() != 0) { _os.writeC(9);
		 * _os.writeC(_item.get_adddex()+_LvStatus.getLvDex());//opqlo 道具升級系統 //
		 * os.writeC(_item.get_adddex()); } if (_item.get_addcon() != 0 ||
		 * _LvStatus.getLvCon() !=0) { _os.writeC(10);
		 * _os.writeC(_item.get_addcon()+_LvStatus.getLvCon()); } if
		 * (_item.get_addwis() != 0 || _LvStatus.getLvWis() !=0) {
		 * _os.writeC(11); _os.writeC(_item.get_addwis()+_LvStatus.getLvWis());
		 * } if (_item.get_addint() != 0 || _LvStatus.getLvInt() !=0) {//opqlo
		 * 道具升級系統 //if (_item.get_addint() != 0) { _os.writeC(12);
		 * //os.writeC(_item.get_addint());
		 * _os.writeC(_item.get_addint()+_LvStatus.getLvInt());//opqlo 道具升級系統 }
		 * if (_item.get_addcha() != 0) { _os.writeC(13);
		 * _os.writeC(_item.get_addcha()); }
		 */
		/*
		 * // HP, MP if (_item.get_addhp() != 0) { os.writeC(14);
		 * os.writeH(_item.get_addhp()); } if (_item.get_addmp() != 0) {
		 * os.writeC(32); os.writeC(_item.get_addmp()); }
		 */
		// MR
		final int mr = this._itemInstance.getMr() + this._LvStatus.getLvMR()
				+ this._itemInstance.getaddMr();
		/*
		 * if (mr !=0) { _os.writeC(15); _os.writeH(mr); }
		 */
		final int Reduction;
		if (this._item.getType2() == 2) {
			final int safe = Math.max(0, this._item.get_safeenchant());
			Reduction = this._item.getDamageReduction()+ this._itemInstance.getLvStatus().getLvDmgReduction()+ (5* Math.max(0, this._itemInstance.getEnchantLevel()- safe));
		} else {
			Reduction = this._item.getDamageReduction()
					+ this._itemInstance.getLvStatus().getLvDmgReduction();
		}
		if (Reduction != 0 || mr != 0) {
			this._os.writeC(39);
			if (mr != 0 && Reduction != 0) {
				this._os.writeS("魔防/減傷:" + mr + " / " + Reduction);
			} else if (Reduction != 0) {
				this._os.writeS("減少傷害:" + Reduction);
			} else {
				this._os.writeS("魔法防禦:" + mr);
			}
		}
		/*
		 * // SP(魔力) if (_item.get_addsp() != 0) { os.writeC(17);
		 * os.writeC(_item.get_addsp()); }
		 */
		// ヘイスト
		if (this._item.isHasteItem()) {
			this._os.writeC(18);
		}
		/*
		 * // 火の属性 if (_item.get_defense_fire() != 0) { os.writeC(27);
		 * os.writeC(_item.get_defense_fire()); } // 水の属性 if
		 * (_item.get_defense_water() != 0) { os.writeC(28);
		 * os.writeC(_item.get_defense_water()); } // 風の属性 if
		 * (_item.get_defense_wind() != 0) { os.writeC(29);
		 * os.writeC(_item.get_defense_wind()); } // 地の属性 if
		 * (_item.get_defense_earth() != 0) { os.writeC(30);
		 * os.writeC(_item.get_defense_earth()); }
		 */

		final int HPR = this._item.get_addhpr() + this._itemInstance.getHpr()
				+ this._LvStatus.getLvHpr();
		final int hp = this._item.get_addhp() + this._itemInstance.getaddHp()
				+ this._LvStatus.getLvHp();
		if (HPR != 0 || hp != 0) {
			this._os.writeC(39);
			if (HPR != 0 && hp != 0) {
				this._os.writeS("血量/回血:" + hp + " / " + HPR);
			} else if (hp != 0) {
				this._os.writeS("體力上限:" + hp);
			} else {
				this._os.writeS("回血:" + HPR);
			}
		}
		final int MPR = this._item.get_addmpr() + this._itemInstance.getMpr()
				+ this._LvStatus.getLvMpr();
		final int mp = this._item.get_addmp() + this._itemInstance.getaddMp()
				+ this._LvStatus.getLvMp();
		if (MPR != 0 || mp != 0) {
			this._os.writeC(39);
			if (MPR != 0 && mp != 0) {
				this._os.writeS("魔量/回魔:" + mp + " / " + MPR);
			} else if (mp != 0) {
				this._os.writeS("魔力上限:" + mp);
			} else {
				this._os.writeS("回魔:" + MPR);
			}
		}

		// TODO 飾品強化卷軸
		/*
		 * if (hp !=0) { _os.writeC(14); _os.writeH(hp); } if (mp !=0) { //
		 * os.writeC(32); // os.writeC(_item.get_addmp() + getaddMp());
		 * _os.writeC(39); if (mp >0) { _os.writeS("魔力上限 +"+mp); }else{
		 * _os.writeS("魔力上限 "+(mp)); } }
		 */
		// TODO 飾品強化卷軸

		// TODO 飾品強化卷軸
		final int sp = this._item.get_addsp() + this._itemInstance.getaddSp()
				+ this._LvStatus.getLvSP();
		if (sp != 0) {
			this._os.writeC(17);
			this._os.writeC(sp);
		}
		// TODO 飾品強化卷軸

		// TODO 飾品強化卷軸
		final int firemr = this._item.get_defense_fire()+ this._itemInstance.getFireMr();

		if (firemr != 0 ) {
			this._os.writeC(39);
			this._os.writeS("火屬性防禦: " + firemr + "%");
		}
		/*
		 * if (firemr != 0) { _os.writeC(27); _os.writeC(firemr); }
		 */
		final int watermr = this._item.get_defense_water()	+ this._itemInstance.getWaterMr();

		if (watermr != 0) {
			this._os.writeC(39);
			this._os.writeS("水屬性防禦: " + watermr + "%");
		}

		/*
		 * if (watermr != 0) { _os.writeC(28); _os.writeC(watermr); }
		 */
		final int windmr = this._item.get_defense_wind()+ this._itemInstance.getWindMr();
		if (windmr != 0) {
			this._os.writeC(39);
			this._os.writeS("風屬性防禦: " + windmr + "%");
		}
		/*
		 * if (windmr != 0) { _os.writeC(29); _os.writeC(windmr); }
		 */
		final int earthmr = this._item.get_defense_earth()+ this._itemInstance.getEarthMr();
		if (earthmr != 0) {
			this._os.writeC(39);
			this._os.writeS("地屬性防禦: " + earthmr + "%");
		}

		/*
		 * if (earthmr != 0) { _os.writeC(30); _os.writeC(earthmr); }
		 */
		// TODO 飾品強化卷軸

		if (this._itemInstance.getStunDice() != 0) {
			this._os.writeC(39);
			this._os.writeS("昏迷成功率 +" + this._itemInstance.getStunDice());
		}
		if (this._itemInstance.getStoneDice() != 0) {
			this._os.writeC(39);
			this._os.writeS("石化成功率 +" + this._itemInstance.getStoneDice());
		}
		if (this._itemInstance.getSleepDice() != 0) {
			this._os.writeC(39);
			this._os.writeS("睡眠成功率 +" + this._itemInstance.getSleepDice());

		}
		if (this._itemInstance.getSustainDice() != 0) {
			this._os.writeC(39);
			this._os.writeS("支撐成功率 +" + this._itemInstance.getSustainDice());
		}
		if (this._itemInstance.getFreezeDice() != 0) {
			this._os.writeC(39);
			this._os.writeS("寒冰成功率 +" + this._itemInstance.getFreezeDice());
		}
		if (this._itemInstance.getBlindDice() != 0) {
			this._os.writeC(39);
			this._os.writeS("暗黑成功率 +" + this._itemInstance.getBlindDice());
		}
		// 凍結耐性
		if (this._item.get_regist_freeze() != 0) {
			this._os.writeC(15);
			this._os.writeH(this._item.get_regist_freeze());
			this._os.writeC(33);
			this._os.writeC(1);
		}
		// 石化耐性
		if (this._item.get_regist_stone() != 0) {
			this._os.writeC(15);
			this._os.writeH(this._item.get_regist_stone());
			this._os.writeC(33);
			this._os.writeC(2);
		}
		// 睡眠耐性
		if (this._item.get_regist_sleep() != 0) {
			this._os.writeC(15);
			this._os.writeH(this._item.get_regist_sleep());
			this._os.writeC(33);
			this._os.writeC(3);
		}
		// 暗闇耐性
		if (this._item.get_regist_blind() != 0) {
			this._os.writeC(15);
			this._os.writeH(this._item.get_regist_blind());
			this._os.writeC(33);
			this._os.writeC(4);
		}
		// スタン耐性
		if (this._item.get_regist_stun() != 0) {
			this._os.writeC(15);
			this._os.writeH(this._item.get_regist_stun());
			this._os.writeC(33);
			this._os.writeC(5);
		}
		// ホールド耐性
		if (this._item.get_regist_sustain() != 0) {
			this._os.writeC(15);
			this._os.writeH(this._item.get_regist_sustain());
			this._os.writeC(33);
			this._os.writeC(6);
		}
		// os.writeC(20);
		// 幸運
		// if (getItem.getLuck() != 0) {
		// os.writeC(20);
		// os.writeC(val);
		// }
		// 種類
		// if (getItem.getDesc() != 0) {
		// os.writeC(25);
		// os.writeH(val); // desc.tbl ID
		// }
		// レベル
		// if (getItem.getLevel() != 0) {
		// os.writeC(26);
		// os.writeH(val);
		// }
	}

	private BinaryOutputStream petitem(final L1PetItem petItem) {

		if (petItem.getUseType() == 1) { // 牙齒
			this._os.writeC(7); // 可使用職業：
			this._os.writeC(128); // [高等寵物]
			this._os.writeC(23); // 材質
			this._os.writeC(this._item.getMaterial());
			this._os.writeD(this._itemInstance.getWeight());
		} else { // 盔甲
			// AC
			this._os.writeC(19);
			int ac = petItem.getAddAc();
			if (ac < 0) {
				ac = ac - ac - ac;
			}
			this._os.writeC(ac);
			this._os.writeC(this._item.getMaterial());
			this._os.writeC(-1); // 飾品級別 - 0:上等 1:中等 2:初級 3:特等
			this._os.writeD(this._itemInstance.getWeight());

			this._os.writeC(7); // 可使用職業：
			this._os.writeC(128); // [高等寵物]

			// STR~CHA
			if (petItem.getAddStr() != 0) {
				this._os.writeC(8);
				this._os.writeC(petItem.getAddStr());
			}
			if (petItem.getAddDex() != 0) {
				this._os.writeC(9);
				this._os.writeC(petItem.getAddDex());
			}
			if (petItem.getAddCon() != 0) {
				this._os.writeC(10);
				this._os.writeC(petItem.getAddCon());
			}
			if (petItem.getAddWis() != 0) {
				this._os.writeC(11);
				this._os.writeC(petItem.getAddWis());
			}
			if (petItem.getAddInt() != 0) {
				this._os.writeC(12);
				this._os.writeC(petItem.getAddInt());
			}
			// HP, MP
			if (petItem.getAddHp() != 0) {
				this._os.writeC(14);
				this._os.writeH(petItem.getAddHp());
			}
			if (petItem.getAddMp() != 0) {
				this._os.writeC(32);
				this._os.writeC(petItem.getAddMp());
			}
			// MR
			if (petItem.getAddMr() != 0) {
				this._os.writeC(15);
				this._os.writeH(petItem.getAddMr());
			}
			// SP(魔力)
			if (petItem.getAddSp() != 0) {
				this._os.writeC(17);
				this._os.writeC(petItem.getAddSp());
			}
		}

		return this._os;
	}

	private BinaryOutputStream weapon() {
		// 打撃値
		final int dmg = this._LvStatus.getLvDmg();
		this._os.writeC(1);
		this._os.writeC(Math.min(127, this._item.getDmgSmall() + dmg));
		this._os.writeC(Math.min(127, this._item.getDmgLarge() + dmg));
		// _os.writeC(_item.getDmgSmall()+dmg);
		// _os.writeC(_item.getDmgLarge()+dmg);
		this._os.writeC(this._item.getMaterial());
		this._os.writeD(this._itemInstance.getWeight());

		// 強化数
		// TODO 飾品強化卷軸
		if (this._itemInstance.getEnchantLevel() != 0) {
			this._os.writeC(2);
			this._os.writeC(this._itemInstance.getEnchantLevel());
		}
		// TODO 飾品強化卷軸

		// 損傷度
		if (this._itemInstance.get_durability() != 0) {
			this._os.writeC(3);
			this._os.writeC(this._itemInstance.get_durability());
		}
		// 両手武器
		if (this._item.isTwohandedWeapon()) {
			this._os.writeC(4);
		}
		final int HitMod = this._item.getHitModifier()
				+ this._LvStatus.getLvHitModifier();
		if (HitMod != 0) {
			// os.writeC(5);
			// os.writeC(getItem().getHitModifier());
			this._os.writeC(39);
			if (HitMod > 0) {
				this._os.writeS("攻擊成功 +" + HitMod);
			} else {
				this._os.writeS("攻擊成功 " + HitMod);
			}
		}
		final int DmgMod = this._item.getDmgModifier()
				+ this._LvStatus.getLvDmgModifier();
		if (DmgMod != 0) {
			// os.writeC(6);
			// os.writeC(getItem().getDmgModifier());
			this._os.writeC(39);
			if (DmgMod > 0) {
				this._os.writeS("額外攻擊點數 +" + DmgMod);
			} else {
				this._os.writeS("額外攻擊點數 " + DmgMod);
			}
		}
		this.OtherStatus();

		return this._os;
	}
}
